<template>
  <div class="detail">
    <el-backtop :right="130"></el-backtop>
    <el-collapse v-model="activeNames" accordion @change="handleChange" style="width:95%;margin:0 auto;" class="parentColl">
      <el-collapse-item title="客户信息" name="1">
        <Customer :changeValue="changeValue" :operation="operation" :projectId="projectId" :isTaskProcessing="true" />
      </el-collapse-item>
      <el-collapse-item title="资产信息" name="2">
        <Assets :changeValue="changeValue" :projectId="projectId" :isTaskProcessing="true" />
      </el-collapse-item>
      <el-collapse-item title="附件信息" name="3">
        <File :changeValue="changeValue" :projectId="projectId" :isTaskProcessing="true"/>
      </el-collapse-item>

   <el-row type="flex" class="row-bg" justify="center" style="margin:50px;">
      <el-col :span="6" >
        <el-button type="primary" @click="backStep" style="width: 120px; height: 40px">上一步</el-button>
        <el-button type="warning" @click="creditStartTask" v-if="projectId != undefined" style="width: 120px; height: 40px">提交</el-button>
        <!-- <el-button type="warning" @click="createData" v-if="submitProjectId === undefined" style="width: 150px; height: 40px">提交</el-button> -->
        <el-button type="warning" @click="creditStartTask" v-else style="width: 120px; height: 40px">重新提交</el-button>
      </el-col>
    </el-row>
    </el-collapse>
  </div>
</template>


<script>
import Customer from '@/views/credit/customer';
import Assets from '@/views/credit/assets';
import File from '@/views/credit/file';
import { submitProject,startTask,returnStepAdd } from '@/api/project';
import { creditStartTask } from '@/api/creditLoan';

export default {
  name: 'detail',
  components: {
    Customer,
    Assets,
    File
  },
   props: {
     taskId: undefined,
  },
  data() {
    return {
      activeNames: undefined,
      name: '11',
      projectId: undefined,
      submitProjectId: undefined,
      operation: undefined,
      changeValue: "detail"
    };
  },
  computed: {},
  created() {
    this.projectId = this.$route.query.projectId;//项目编辑传递项目ID
    if (this.projectId === undefined){
      this.projectId = localStorage.getItem('projectId');
    }
    this.submitProjectId = this.$route.query.submitProjectId;//重新提交传递项目ID
    this.operation = this.$route.query.operation;//操作
  },
  methods: {
    handleChange(val) {
      console.log(val);
    },
    stepChange(currentStep) {
      this.currentStep = currentStep;
    },
    backStep() {
      this.$emit('stepChanged', 3);
    },
    creditStartTask(row) {
      this.$confirm('确定提交此笔进件项目吗', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
        creditStartTask(this.projectId == undefined ? this.submitProjectId : this.projectId)
            .then((data) => {
             this.$notify({
                title: '成功',
                message: '提交成功',
                type: 'success'
                 });
            this.$router.push("/project/index")
                  })
            .catch((err) => {
              console.error('提交失败');
            });
        }).catch((e) => {
          console.log(e)
           this.$message("已取消提交")
        });
    },
    createData() {
      var queryProjectId = undefined;
      if (this.projectId === undefined) {
        queryProjectId = localStorage.getItem('projectId');
      }
      this.$confirm('你确定要提交吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        // 开始提交信息
        submitProject(queryProjectId).then((data) => {
          this.$notify.success('提交成功');
          this.$router.push("/project/index")
        });
      });
    },
    // 重新提交
    returnStepAdd() {
      var queryProjectId = undefined;
      if (this.projectId === undefined) {
        queryProjectId = localStorage.getItem('projectId');
      }
      this.$confirm('你确定要提交吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        // 开始提交信息
        returnStepAdd(queryProjectId,this.taskId).then((data) => {
          this.$notify.success('提交成功');
          this.$router.push("/project/index")
        });
      });
    },
  },
};
</script>

<style scoped>
.parentColl >>> .el-collapse-item__header {
  min-height: 95px;
  font-size: 20px;
  font-weight: 1000;
  padding: 20px;
}
</style>
